package controller

import (
	"app-webapi/comm"
	"app-webapi/comm/g"
	"app-webapi/comm/response"
	"app-webapi/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

// GetVerificationCode 获取验证
func GetVerificationCode(c *gin.Context) {
	service.Captcha(c, 4)
}

func GetCaptcha(c *gin.Context) {
	id, base64s, _ := comm.GenerateCaptcha()
	data := map[string]interface{}{"captchaId": id, "captchaImg": base64s}
	response.Success("操作成功", data, c)
}

// CaptchaVerify 验证码校验
func CaptchaVerify(c *gin.Context) {
	captcha := c.Param("captcha")
	if service.CaptchaVerify(c, captcha) {
		c.JSON(http.StatusOK, g.JsonResult{
			Message:    "验证码正确",
			StatusCode: http.StatusOK,
		})
	} else {
		c.JSON(http.StatusUnauthorized, g.JsonResult{
			Message:    "验证码错误",
			StatusCode: http.StatusUnauthorized,
		})
	}
}
